# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/10 21:48
# @Author   : Robot-Zsj
"""
description:

input
1 2 3 4 5 6 7 8 9 10
output
1
"""

arr = list(map(int, input().split()))


def dfs(arr, index, level, sumV, res):
    if level == 5:
        res.append(sumV)
        return

    for i in range(index, 10):
        if i > index and arr[i] == arr[i - 1]:
            continue
        dfs(arr, i + 1, level + 1, sumV + arr[i], res)


def getResult(arr):
    arr.sort()

    res = []

    dfs(arr, 0, 0, 0, res)

    sumV = sum(arr)

    return min(map(lambda subSum: abs(sumV - 2 * subSum), res))


print(getResult(arr))
